clear; clc; close all;

knots = [30,60];
x = [1:100]';
n = length(x);
b0 = 3; b1 = -4; b2 = 4;                                    b3 = 6;
                I2 = zeros(n,1); I2(knots(1):end) = 1;     I3 = zeros(n,1); I3(knots(2):end) = 1;
                
y = b0 + b1*x + b2*(x-knots(1)).*I2 + b3*(x-knots(2)).*I3 + rand(n,1)*10;

plot(x,y,'.'); grid on

A = [ones(n,1) x (x-knots(1)).*I2 (x-knots(2)).*I3];
b_est = pinv(A'*A)*A'*y